﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VgoCardChange.Models.Objects;
using VgoCardChange.Models;

namespace VgoCardChange.Controllers
{
    public class RoleController : Controller
    {
        //
        // GET: /Role/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult GetRoles()
        {
            List<Role> listrole = new List<Role>();
            RoleModels RoleMd = new RoleModels();
            listrole = RoleMd.GetRoles();
            ViewData["listrole"] = listrole;
            return View();

        }
        public ActionResult CreateRole()
        {
      
            return View();
        }
        [HttpPost]
        public ActionResult CreateRole(string RoleName, string Desciption)
        {
            RoleModels RoleMd = new RoleModels();
            Role role = new Role();
            role.RoleName = RoleName;
            role.Desciption = Desciption;
            RoleMd.CreateRole(role);
            return RedirectToAction("GetRoles");
        }
        public ActionResult EditRole(int RoleID)
        {
            RoleModels RoleMd = new RoleModels();
            List<Role> listroledid = new List<Role>();
            listroledid = RoleMd.GetRoleID(RoleID);
            ViewData["listroleid"] = listroledid;
            return View();
        }
        [HttpPost]
        public ActionResult EditRole(int RoleID, string RoleName, string Desciption)
        {
            RoleModels RoleMd = new RoleModels();
            Role role = new Role();
            role.RoleID = RoleID;
            role.RoleName = RoleName;
            role.Desciption = Desciption;
            RoleMd.EditRole(role);
            return RedirectToAction("GetRoles");

        }
        public ActionResult DeleteRole(int RoleID)
        {
            RoleModels RoleMd = new RoleModels();
            List<Role> listroledid = new List<Role>();
            listroledid = RoleMd.GetRoleID(RoleID);
            ViewData["listroleid"] = listroledid;
            return View();
        }
        [HttpPost]
        public ActionResult DeleteRole(int RoleID, FormCollection coll)
        {
            RoleModels RoleMd = new RoleModels();
            RoleMd.DeleteRole(RoleID);
            return RedirectToAction("GetRoles");
        }



    }
}
